import syRequest from "@/service"

// 更新用户昵称
export function updateName(newName: string) {
  return syRequest.patch({
    url: "/users/updateName",
    data: {
      newName
    }
  })
}

// 更新用户头像
export function updateAvatar(newAvatar: string) {
  return syRequest.patch({
    url: "/users/updateAvatar",
    data: {
      newAvatar
    }
  })
}

// 获取用户信息
export function getUserInfo() {
  return syRequest.get({
    url: "/users/getUserInfo"
  })
}

// 获取用户关注
export function getUserAttention(limit, offset) {
  return syRequest.get({
    url: `/users/getUserAttention`,
    params: {
      limit,
      offset
    }
  })
}

// 获取用户点赞，收藏，发布的文章
export function getUserArticle(classify: "Support" | "Save" | "Publish", limit, offset) {
  return syRequest.get({
    url: `/users/getUser${classify}`,
    params: {
      limit,
      offset
    }
  })
}

// 推荐用户
export function recommendUsers(limit, uid?) {
  return syRequest.get({
    url: `/users/recommendUsers`,
    params: {
      limit,
      uid
    }
  })
}

// 关注用户
export function attentionUser(uid) {
  return syRequest.post({
    url: `/users/attentionUser/${uid}`
  })
}

// 取消关注用户
export function cancelAttentionUser(uid) {
  return syRequest.delete({
    url: `/users/cancelAttentionUser/${uid}`
  })
}

// 获取是否关注用户
export function isAttentionUser(uid) {
  return syRequest.get({
    url: `/users/isAttentionUser/${uid}`
  })
}

/* 获取是否收藏点赞文章 */
export function isOperateArticle(operateFun: "Save" | "Support", article_id) {
  return syRequest.get({
    url: `/users/is${operateFun}Article/${article_id}`
  })
}

/* 获取用户所在地区的救助热线 */
export function getUserRescueHotline(province) {
  return syRequest.get({
    url: `/users/getUserRescueHotline`,
    params: {
      province
    }
  })
}
